import React, { PropTypes } from 'react'
import { routerRedux } from 'dva/router'
import { connect } from 'dva'
import { Spin } from 'antd'
import GoodsIntoList from '../components/goodsinto/list'
import GoodsIntoModal from '../components/goodsinto/modal'
import GoodsIntoSearch from '../components/goodsinto/search'

//调运商品入柜
function GoodsInto ({location,dispatch,app,goodsInto}) {
	const {list,loading,pagination,modalVisible,number,shelfId,amount,item} = goodsInto
	
	const goodsIntoModalProps = {
		visible: modalVisible,
		type: '',
		item: item,
		onOk(data){
			console.log(data.goods_name)
			dispatch({
				type: 'goodsInto/update',
				payload: data
			})
		},
		onCancel() {
			dispatch({
				type: 'goodsInto/hideModal'
			})
		}
	};
	const goodsIntoListProps = {
		dataSource: list,
		loading,
		pagination: pagination,
		onPageChange(page) {
			const { query, pathname } = location;
			dispatch(routerRedux.push({
				pathname: pathname,
				query: {
					...query,
					page: page.current,
					pageSize: page.pageSize
				}
			}))
		},
		onQuerySelected(query, page) {
			dispatch({
				type: 'goodsInto/queryState',
				payload: {
					query,
					page
				}
			})
		},
		// onDeleteItem(id) {
		// 	dispatch({
		// 		type: 'goodsInto/delete',
		// 		payload: id
		// 	})
		// },
		onEditItem(item) {
			dispatch({
				type: 'goodsInto/showModal',
				payload: {
					modalType: 'update',
					currentItem: item
				}
			})
		},
	};
	const goodsIntoSearchProps = {
		number: number,
		shelfId: shelfId,
		amount: amount,
		onSearch(code){
			//搜索后翻页记录的显示
			// const {	query,pathname} = location; 
			// query.code = code;
			// history.pushState(query, 'TS', 'http://127.0.0.1:8000/main-dev.html#' + pathname)

			dispatch({
				type: 'goodsInto/search',
				payload: {
					code: code
				}
			})
		},
		onRefresh(){
			dispatch({
					type: 'goodsInto/update'
				})
		},
		onGoodsIn(params){
				dispatch({
						type: 'goodsInto/create',
						payload: {...params	}
					})
		},
		resetParams(){
			dispatch({
				type: 'goodsInto/reset'
			})
		}
	}
	const GoodsIntoModalGen = () =>
		<GoodsIntoModal {...goodsIntoModalProps} />;
	return(
		<div className='content-inner'>
	      <Spin tip='loading...' spinning={loading} size='large'>
	       <GoodsIntoSearch {...goodsIntoSearchProps} />
	        <GoodsIntoList {...goodsIntoListProps} />	       
	        <GoodsIntoModalGen />
	      </Spin>
	    </div>
	)
}
GoodsInto.propTypes = {
  GoodsInto: PropTypes.object,
  location: PropTypes.object,
  dispatch: PropTypes.func
};

function mapStateToProps({app,goodsInto}){
	return {app,goodsInto}
}

export default connect(mapStateToProps)(GoodsInto)